package com.ys.controller.api.flow;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ys.entity.sys.YsProcInst;
import com.ys.enume.flow.YsProcInstEnum;
import com.ys.enume.flow.YspTaskAuditUserEnum;
import com.ys.util.shiro.ShiroUtils;
import com.ys.vo.R;

import lombok.AllArgsConstructor;
import lombok.Data;

@Controller
@RequestMapping("/api/inter/task")
public class ApiInterTaskController {
	
	/**
	 * 加载数据
	 */
	@PostMapping("/index")
    @ResponseBody
	public R index(Model model, HttpServletRequest request, HttpServletResponse response){
		
		String loginUserId = ShiroUtils.getUserId();
		
		Integer numInit = new YsProcInst().setStatus(1).setStateFlow(YsProcInstEnum.StateFlow.INIT.value)
				.setCreateUserId(loginUserId).count();
		Integer numProcess = new YsProcInst().setStatus(1).setStateFlow(YsProcInstEnum.StateFlow.PROCESS.value)
				.where("A.TaskId in (select TaskId from YSP_TaskAuditUser where UserId = '" + loginUserId + "' and State = " + YspTaskAuditUserEnum.State.FOR_AUDIT.value + ")")
				.count();
		IndexDto dto = new IndexDto(numInit, numProcess);
		
		return R.ok(dto);
	}
	
	@Data
	@AllArgsConstructor
	public static class IndexDto {
		private Integer numInit; // 制单中任务数
		private Integer numProcess; // 待处理任务数
	}
}
